package com.java.basis.collection.set;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author wangning
 * @create 2021-04-21 21:40
 */
public class TestSet01 {
	public static void main(String[] args) {
		//创建集合
		Set<String> set = new HashSet<>();
		//1.添加数据
		set.add("华为");
		set.add("苹果");
		set.add("小米");
		set.add("华为");
		System.out.println("set.toString() = " + set.toString());

		//2.删除数据
//		set.remove("小米");
//		System.out.println("set.toString() = " + set.toString());

		//3.遍历数据【重点】
		//3.1使用增强for
		System.out.println("-------增强for-------");
		for (String string : set) {
			System.out.println(string);

		}
		//3.2使用迭代器
		Iterator<String> iterator = set.iterator();
		while (iterator.hasNext()) {
			String next = iterator.next();
		}

		//4.判断
		set.contains("华为");
		set.isEmpty();

		System.out.println(set.toArray());
	}
}
